import 'package:bigegg/page/main/page/im/page/xmm_conversation_page.dart';
import 'package:bigegg/page/main/page/im/page/xmm_follow_page.dart';
import 'package:bigegg/widget/xmm_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class XmmImPage extends StatefulWidget {
  const XmmImPage({super.key});

  @override
  State<StatefulWidget> createState() {
    return XmmImPageState();
  }
}

class XmmImPageState extends State<XmmImPage>
    with AutomaticKeepAliveClientMixin, TickerProviderStateMixin {
  @override
  bool get wantKeepAlive => true;

  final _selectIndex = 0.obs;

  final PageController _controller = PageController(initialPage: 0);

  final List<Widget> _tabPages = [
    const XmmConversationPage(),
    const XmmFollowPage(),
  ];

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      body: Container(
        padding: EdgeInsets.only(top: context.mediaQueryPadding.top + 5.w),
        decoration: commonBgDecoration(bgImage: "assets/images/xmm_bg_home.png"),
        child: Column(children: [
          Row(children: [
            GestureDetector(
              onTap: () {
                _selectIndex.value = 0;
                _controller.jumpToPage(0);
              },
              child: Container(
                alignment: Alignment.center,
                margin: EdgeInsets.only(left: 40.w),
                width: 110.w,
                height: 33.w,
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(52),
                ),
                child: Obx(
                  () => Text(
                    "Messages",
                    style: TextStyle(
                      fontSize: 16.sp,
                      color: Color(
                          _selectIndex.value == 0 ? 0xFF3E3E3E : 0xFFB2B2B2),
                    ),
                  ),
                ),
              ),
            ),
            const Expanded(child: SizedBox()),
            GestureDetector(
              onTap: () {
                _selectIndex.value = 1;
                _controller.jumpToPage(1);
              },
              child: Container(
                alignment: Alignment.center,
                margin: EdgeInsets.only(right: 40.w),
                width: 89.w,
                height: 33.w,
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(52),
                ),
                child: Obx(
                  () => Text(
                    "Followed",
                    style: TextStyle(
                      fontSize: 16.sp,
                      color: Color(
                          _selectIndex.value == 1 ? 0xFF3E3E3E : 0xFFB2B2B2),
                    ),
                  ),
                ),
              ),
            ),
          ]),
          Expanded(
            child: Container(
              margin: EdgeInsets.only(top: 22.w),
              child: PageView(
                controller: _controller,
                //设置不可滑动
                physics: const NeverScrollableScrollPhysics(),
                children: _tabPages,
              ),
            ),
          )
        ]),
      ),
    );
  }
}
